package valleyOfDemon;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * 请求对象获取请求头的一些信息
 */
@WebServlet("/ServletDemo02")
public class ServletDemo02 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println(getServletContext().getAttribute("姜衡一家子"));
        //System.out.println(req.getHeader("host"));//localhost:8080
        Enumeration<String> accept = req.getHeaders("accept");
        while (accept.hasMoreElements()) {
            System.out.println(accept.nextElement());
        }
        //text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,
        //*/*;q=0.8,application/signed-exchange;v=b3;q=0.9

        Enumeration<String> headerNames = req.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            System.out.println(headerNames.nextElement());
        }
        /*
        host
        connection
        cache-control
        sec-ch-ua
        sec-ch-ua-mobile
        upgrade-insecure-requests
        user-agent
        accept
        sec-fetch-site
        sec-fetch-mode
        sec-fetch-user
        sec-fetch-dest
        accept-encoding
        accept-language
        cookie
         */
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
